package com.sharemarking.system.service;

import com.sharemarking.wa.common.ResponseParams;
import com.sharemarking.wa.common.exception.RequestException;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

import static com.sharemarking.wa.common.SysHttpStatus.REQUIRED_PARAMS_ERROR;

/**
 * @author dxy
 */
@Service("timeService")
public class TimeService {

    /*
     * 将时间戳转换为时间
     */
    public String getStringToDate(Integer time) throws Exception {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Long lt = new Long(time);
            Date date = new Date(lt);
            return format.format(date);
        } catch (Exception e) {
            throw RequestException.create(ResponseParams.error(REQUIRED_PARAMS_ERROR));
        }
    }

}
